<?php
// SETTINGS
include("../../settings.inc.php");
    $table = new Tables;

// PHP
include("../../php/php.php");
    $php = new PHP;

// DATABASE
include("../../db/mysql.php");
    $db = new DB;
    // connect to the datbase
    $db->connect();

// SESSIONS
include("../../session/session.php");
    $session = new Session;
    $session->init();

// HTML
include("../../html/html.php");
    $html = new HTML;

// HTML FORMS
include("../../form/form.php");
    $html_form = new HTMLForm;

// COMMON HTML TEXT
include("../../common/common.php");
    $common = new Common;

$charset = $_GET['cs'];
$language = $_GET['lang'];
$action = getAction($_GET['action']);
?>

<html>
<head>
<META HTTP-EQUIV="Content-Type" content="text/html; charset=<?php echo $charset; ?>">
<style>
BODY {	MARGIN-TOP:00pt; MARGIN-BOTTOM:00pt; FONT-SIZE: 8pt; COLOR: #000000; FONT-FAMILY: Verdana,Arial,Tahoma; FONT-WEIGHT: normal; background-color:#ffffff; border-top:1pt solid; border-bottom:1pt solid; border-left:1pt solid; border-right:1pt solid }
P {	margin-top:0pt; margin-bottom:0pt;}
A:link {	COLOR: #0080c0; FONT-WEIGHT: normal; TEXT-DECORATION: underline}
A:visited {	COLOR: #0080c0; FONT-WEIGHT: normal; TEXT-DECORATION: underline}
A:active {	COLOR: #0080c0; FONT-WEIGHT: normal; TEXT-DECORATION: underline}
A:hover {	COLOR: #40c0ff; FONT-WEIGHT: normal; TEXT-DECORATION: underline}

TABLE { BORDER: 0pt }

TH { BACKGROUND-COLOR:#00486a; FONT-SIZE: 8pt; COLOR: #64b5db; FONT-FAMILY: Arial,Verdana,Tahoma; FONT-WEIGHT: bold}
TD { FONT-SIZE: 8pt; COLOR: #000000; FONT-FAMILY: Verdana,Arial,Tahoma; FONT-WEIGHT: normal}
TD.navmenu { FONT-SIZE: 7.5pt; COLOR: #000000; FONT-FAMILY: Verdana,Arial,Tahoma; FONT-WEIGHT: normal}
TD A:link {	   COLOR: #006595; FONT-WEIGHT: normal; TEXT-DECORATION: none}
TD A:visited { COLOR: #006595; FONT-WEIGHT: normal; TEXT-DECORATION: none}
TD A:active {  COLOR: #006595; FONT-WEIGHT: normal; TEXT-DECORATION: none}
TD A:hover {   COLOR: #64b5db; FONT-WEIGHT: normal; TEXT-DECORATION: underline}

.blue { COLOR: #0381d6; }
.1px_border { BORDER: 1pt #00486a SOLID; }
.menu,.menu A:link,.menu A:visited,.menu A:active,.menu A:hover { font-size:7.5pt; font-weight: bold }

FORM {	FONT-SIZE: 8pt; FONT-FAMILY: Verdana,Arial,Tahoma; MARGIN-TOP: 0pt; MARGIN-BOTTOM: 0pt }
INPUT,TEXTAREA,SELECT { COLOR: #00486a; FONT-SIZE: 8pt; FONT-FAMILY: Verdana,Arial,Tahoma; BORDER: #000000 1px solid; BACKGROUND-COLOR: #64b5db}
INPUT.checkbox { background:none; border:0pt; }
INPUT.radio { background:none; border:0pt; }
INPUT.submit { background-color:#006595; color:#ffffff }

INPUT.admin { background-color:#cccccc; font-family:Courier New,System; color:#000000; font-size:9pt }
TEXTAREA.admin { background-color:#cccccc; font-family:Courier New,System; color:#000000; font-size:9pt }
</style>
</head>
<script language=JavaScript>
function insertAtCaret (icon1, icon2) 
{ 
    if (window.parent.document.pagecreator.pagecontent.createTextRange && window.parent.document.pagecreator.pagecontent.caretPos) 
    { 
        var caretPos = window.parent.document.pagecreator.pagecontent.caretPos; 
        selectedtext = caretPos.text; 
        caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? icon1 : icon1; 
        caretPos.text = caretPos.text + selectedtext + icon2; 
    } 
    else window.parent.document.pagecreator.pagecontent.value = window.parent.document.pagecreator.pagecontent.value + icon1 + icon2;
    window.parent.document.pagecreator.pagecontent.focus();
	
	window.location = 'about:blank';
}
</script>
</body>
<?php

if ($action == "urlid")
{
    $content.= selectLocalID($language, $parent = 0, $depth = 1);
}
else
{
    $content.= selectLocalID($language, $parent = 0, $depth = 1);
}


// Print Page
echo $content;

// FUNCTIONS

function getAction($action = "")
{
    if (!eregi("^(urlid|color)$", $action)) { $action = ""; }
	return $action;
}


function selectLocalID($language)
{
    global $table,$db,$html,$html_form;
	
	    $str.= "<p><b>ROOT</b></p>";
		    $result = $db->query("SELECT * FROM $table->page WHERE dir='0' AND language='$language' ORDER BY name");
		    while ($row = $db->nextRecord($result))
	        {
			    $str.= showPage($row->name, $row->id, 0);
			}
		$str.=getChild($language);
	
	return $str;
}


function getChild($language, $parent = 0, $depth = 1) {
    global $db,$table;
	
	$str = "";
	
	$result = $db->query("SELECT * FROM $table->dir WHERE parent='$parent' AND language='$language' ORDER BY name");
	while ($row = $db->nextRecord($result))
	{
	    $str.= showDir($row->name, $depth);
		
		$result2 = $db->query("SELECT * FROM $table->page WHERE dir='$row->id' AND language='$language' ORDER BY name");
		    while ($row2 = $db->nextRecord($result2))
	        {
			    $str.= showPage($row2->name, $row2->id, $depth);
			}
		
	    $str.= getChild($language, $row->id, $depth+1);
	}
	
	return $str;
}


function showDir($name, $depth)
{
    $left = $depth*12;
    $str = "<p style='margin-left:".$left."pt'><img src='../images/subdir.gif' border='0'> $name</p>";
	return $str;
}


function showPage($name, $id, $depth)
{
    global $action;
	
	if ($action == "urlid") { $options = "'[url=$id]','[/url]'"; } else { $options = "'=$id',''"; }
    $left = $depth*12;
	$str.= "<p style='margin-left:".$left."pt'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
	$str.= "<img src='../images/page.gif' border='0'>";
	$str.= "&nbsp;<a href=\"javascript:insertAtCaret($options)\">$name</a></p>";
	return $str;
}
?>
</body>
</html>